Procesamiento de imagenes con matplotlib

Una imagen digital es simplemente un arreglo de datos (similar a una matriz), donde cada elemento corresponde a la informacion de cada pixel.

0 1 2 3 4
0 10 15 6 7 8
1 1 4 12 6 10
2 0 11 25 20 10
3 9 7 4 21 7
4 5 10 5 0 12

In [1]:
import matplotlib.pyplot as plt
%matplotlib inline

In [2]:
imagen=plt.imread("img/caracol.jpg")

In [3]:
imagen


Out[3]:
array([[[209, 187, 112],
        [206, 184, 109],
        [210, 188, 113],
        ..., 
        [210, 187, 111],
        [209, 183, 108],
        [205, 179, 104]],

       [[207, 185, 110],
        [208, 186, 111],
        [212, 190, 115],
        ..., 
        [213, 187, 112],
        [214, 188, 113],
        [213, 187, 112]],

       [[207, 185, 110],
        [211, 189, 114],
        [212, 190, 115],
        ..., 
        [210, 184, 107],
        [211, 185, 108],
        [212, 185, 108]],

       ..., 
       [[212, 177,  83],
        [214, 179,  85],
        [216, 181,  87],
        ..., 
        [189, 130,  40],
        [185, 126,  32],
        [182, 124,  25]],

       [[215, 180,  88],
        [218, 183,  89],
        [218, 183,  89],
        ..., 
        [195, 133,  46],
        [181, 120,  27],
        [174, 114,  16]],

       [[216, 181,  89],
        [220, 185,  93],
        [218, 183,  89],
        ..., 
        [173, 111,  24],
        [162, 101,   8],
        [160, 100,   2]]], dtype=uint8)

In [4]:
plt.imshow(imagen)


Out[4]:
<matplotlib.image.AxesImage at 0x7f50f049c240>

In [5]:
plt.figure(figsize=(10,10))
plt.imshow(imagen)


Out[5]:
<matplotlib.image.AxesImage at 0x7f50ec14a0b8>

In [6]:
plt.figure(figsize=(10,10))
plt.imshow(255-imagen)


Out[6]:
<matplotlib.image.AxesImage at 0x7f50ec0dc438>

In [18]:
plt.figure(figsize=(10,10))
plt.imshow(imagen[:,:,0],cmap="Greys")


Out[18]:
<matplotlib.image.AxesImage at 0x7f50e73ba518>

In [20]:
plt.figure(figsize=(10,10))
plt.imshow(255-imagen[:,:,0],cmap="Greys")


Out[20]:
<matplotlib.image.AxesImage at 0x7f50e725c710>

In [9]:
imagen.shape


Out[9]:
(910, 512, 3)

In [10]:
imagen.size


Out[10]:
1397760

In [11]:
imagen.min()


Out[11]:
0

In [12]:
imagen.max()


Out[12]:
255

Ejercicio:

Muestra por aparte cómo se ve cada canal de R, G, y B usando un cmap acorde con el color del canal.

Glitch

Hay muchas maneras de glitchear digitalmente una imagen:


In [13]:
imagen**2


Out[13]:
array([[[161, 153,   0],
        [196,  64, 105],
        [ 68,  16, 225],
        ..., 
        [ 68, 153,  33],
        [161, 209, 144],
        [ 41,  41,  64]],

       [[ 97, 177,  68],
        [  0,  36,  33],
        [144,   4, 169],
        ..., 
        [ 57, 153,   0],
        [228,  16, 225],
        [ 57, 153,   0]],

       [[ 97, 177,  68],
        [233, 137, 196],
        [144,   4, 169],
        ..., 
        [ 68,  64, 185],
        [233, 177, 144],
        [144, 177, 144]],

       ..., 
       [[144,  97, 233],
        [228,  41,  57],
        [ 64, 249, 145],
        ..., 
        [137,   4,  64],
        [177,   4,   0],
        [100,  16, 113]],

       [[145, 144,  64],
        [164, 209, 241],
        [164, 209, 241],
        ..., 
        [137,  25,  68],
        [249,  64, 217],
        [ 68, 196,   0]],

       [[ 64, 249, 241],
        [ 16, 177, 201],
        [164, 209, 241],
        ..., 
        [233,  33,  64],
        [132, 217,  64],
        [  0,  16,   4]]], dtype=uint8)

In [14]:
plt.figure(figsize=(10,10))
plt.imshow(imagen**2)


Out[14]:
<matplotlib.image.AxesImage at 0x7f50e76d5518>

In [ ]:
plt.imshow?